package leetcode_1301_1400;

public class LeeCode_1330 {
    public static void main(String[] args) {

    }
    private static int maxValueAfterReverse(int[] nums) {
        int n = nums.length;
        int sum = 0;
        for (int i = 1; i < n; i++) {
            sum += Math.abs(nums[i] - nums[i - 1]);
        }
        int mx1 = 0;
        for (int i = 1; i < n - 1; i++) {
            mx1 = Math.max(mx1, Math.abs(nums[i] - nums[0]) - Math.abs(nums[i] - nums[i - 1]));
            mx1 = Math.max(mx1, Math.abs(nums[n - 1] - nums[i]) - Math.abs(nums[i + 1] - nums[i]));
        }
        int mx2 = Integer.MIN_VALUE, mn2 = Integer.MAX_VALUE;
        for (int i = 0; i < n - 1; i++) {
            int x = nums[i], y = nums[i + 1];
            mx2 = Math.max(mx2, Math.min(x, y));
            mn2 = Math.min(mn2, Math.max(x, y));
        }
        return sum + Math.max(mx1, (mx2 - mn2) * 2);
    }
}
